package ansi.servlet.pago_de_cuotas;

import java.io.IOException;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import ansi.negocio.GestionPago_Cuota;
import javax.servlet.RequestDispatcher;
import ansi.util.Texto;

/**
 * Servlet implementation class RegistroPagoDeCuotasServlet
 */
@WebServlet("/RegistroPagoDeCuotasServlet")
public class RegistroPagoDeCuotasServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * Default constructor. 
     */
    public RegistroPagoDeCuotasServlet() {
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		try {
			GestionPago_Cuota gestionPago_Cuota = new GestionPago_Cuota();
			String TipoPago = Texto.getStr(request.getParameter("TipoPago"));
			Date FechaPago = Texto.getDateFromStr(request
					.getParameter("FechaPago"));
			Integer idCuota = Texto.getInt(request.getParameter("idCuota"));
			if (idCuota != null && idCuota != 0) {
				gestionPago_Cuota.actualizar(TipoPago, FechaPago, idCuota);
			} else {
				gestionPago_Cuota.insertar(TipoPago, FechaPago, idCuota);
			}
			request.setAttribute("MENSAJE", " El registro fue realizado");
			RequestDispatcher rd = request
					.getRequestDispatcher("pagocuota_nuevo.jsp");
			rd.forward(request, response);
		} catch (Exception ex) {
			ex.printStackTrace();
		}

	}

}
